package com.fulu.game.bi.controller.value;

import com.fulu.game.bi.AssertHelper;
import com.fulu.game.bi.common.exception.BizException;
import com.fulu.game.bi.entity.bo.channel.ValueSceneListBO;
import com.fulu.game.bi.entity.dto.ValueSceneListDTO;
import com.fulu.game.bi.entity.enums.ValueCategoryEnum;
import com.fulu.game.bi.entity.vo.Result;
import com.fulu.game.bi.entity.vo.common.NameMsgVO;
import com.fulu.game.bi.redis.service.value.ValueAddService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 增值-增值场景
 */
@RestController
@RequestMapping("/api/value/scene")
@Slf4j
public class ValueSceneController {

    @Autowired
    private ValueAddService valueAddService;

    /**
     * 增值场景-实时数据
     */
    @RequestMapping("/real-time")
    public Result realTime(Integer category) {
        AssertHelper.assertNotNull(category, () -> new BizException("礼物类型不能为空"));
        return Result.success().data(valueAddService.realTime(category));
    }

    /**
     * 增值场景-列表
     */
    @RequestMapping("/list")
    public Result list(@Validated ValueSceneListDTO valueSceneListDTO) {
        ValueSceneListBO valueSceneListBO = new ValueSceneListBO();
        BeanUtils.copyProperties(valueSceneListDTO, valueSceneListBO);
        return Result.success().data(valueAddService.list(valueSceneListBO));
    }

    /**
     * 增值场景-导出
     */
    @RequestMapping("/export")
    public void export(ValueSceneListDTO valueSceneListDTO) {
        ValueSceneListBO valueSceneListBO = new ValueSceneListBO();
        BeanUtils.copyProperties(valueSceneListDTO, valueSceneListBO);
        valueAddService.export(valueSceneListBO);
    }

    /**
     * 增值场景-折线图
     *
     * @return
     */
    @RequestMapping("/line-chart")
    public Result<List<NameMsgVO>> stat(Integer category) {
        Map<String, String> cacheMap = new LinkedHashMap<>();
        ValueCategoryEnum anEnum = ValueCategoryEnum.getEnum(category);
        switch (anEnum) {
            case GIFT: {
                cacheMap.put("消费人数", "consumeUserNum");
                cacheMap.put("消费次数", "consumeNum");
                cacheMap.put("消费金额", "virtualMoneyAll");
                cacheMap.put("魅力值", "charmMoneyAll");
                cacheMap.put("消费数量", "amount");
                break;
            }
            case TREASURE_CHEST: {
                cacheMap.put("开启人数", "consumeUserNum");
                cacheMap.put("开启次数", "consumeNum");
                cacheMap.put("开启数量", "amount");
                cacheMap.put("消费金额", "virtualMoneyAll");
                cacheMap.put("魅力值", "charmMoneyAll");
                cacheMap.put("宝箱收益", "earnings");
                break;
            }
            case GIFT_BOX: {
                cacheMap.put("消费人数", "consumeUserNum");
                cacheMap.put("消费次数", "consumeNum");
                cacheMap.put("消费数量", "amount");
                cacheMap.put("消费金额", "virtualMoneyAll");
                cacheMap.put("魅力值", "charmMoneyAll");
                cacheMap.put("礼盒收益", "earnings");
                break;
            }
            default:
                break;
        }
        List<NameMsgVO> list = cacheMap.entrySet().stream()
                .map(entry -> {
                    NameMsgVO idNameVO = new NameMsgVO();
                    idNameVO.setName(entry.getValue());
                    idNameVO.setMsg(entry.getKey());
                    return idNameVO;
                })
                .collect(Collectors.toList());
        return Result.success().data(list).msg("获取成功");
    }


    /**
     * 增值场景-折线图-列表
     *
     * @return
     */
    @RequestMapping("/line-list")
    public Result lineList(@Validated ValueSceneListDTO valueSceneListDTO) {
        ValueSceneListBO valueSceneListBO = new ValueSceneListBO();
        BeanUtils.copyProperties(valueSceneListDTO, valueSceneListBO);
        return Result.success().data(valueAddService.lineList(valueSceneListBO)).msg("获取成功");
    }

}
